package pile;

import java.util.PriorityQueue;

public class findKthLargest2 {
    public int findKthLargest(int[] nums, int k) {
        //小根堆
        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for(int i =0;i<k;i++) {
            queue.offer(nums[i]);
        }
        for(int i =k;i<nums.length;i++) {
            if(nums[i] > queue.peek()){
                queue.poll();
                queue.offer(nums[i]);
            }
        }
        return queue.poll();
    }
}
